<template>
  <!-- 终端工单处理报表 -->
  <div class="clientOrderHand">
    <ContentWrap>
      <FormContainer :column="3">
        <el-form ref="form" :model="formData" :rules="formRules" label-width="80px">
          <el-form-item prop="operationMode" label="统计对象">
            <el-select v-model="formData.operationMode" filterable clearable>
              <el-option label="办事处" value="01" />
              <el-option label="经销商" value="02" />
            </el-select>
          </el-form-item>
          <!-- <el-form-item v-if="formData.operationMode==='02'" :prop="formData.operationMode==='02'?'disCode':''" label="经销商">
            <SearchSelectPicker
              ref="serviceSelect"
              url="/call-center/api/v1/mscInfo/dealer/page"
              placeholder="请选择经销商"
              :params="{query:null,type:1}"
              value-name="code"
              lable-name="name"
              :value.sync="formData.disCode"
            ></SearchSelectPicker>
          </el-form-item>
          <el-form-item v-if="formData.operationMode==='01'" prop="officeCode" label="办事处">
            <SearchSelectPicker
              url="/call-center/api/v1/mscInfo/office/ref/page"
              method="get"
              placeholder="请选择办事处"
              lable-name="name"
              value-name="code"
              :value.sync="formData.officeCode"
              clearable
            ></SearchSelectPicker>
          </el-form-item> -->
          <el-form-item prop="queryDate" label="派单日期">
            <el-date-picker
              v-model="formData.queryDate"
              type="daterange"
              opt
              value-format="yyyy-MM-dd"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            />
          </el-form-item>
          <el-form-item
            prop="buyChannel"
            label="购买渠道"
          >
            <CustomDictSelect
              placeholder="请选择"
              dict-type-code="PURCHASE_CHANNEL"
              bind-name="dictName"
              bind-value="dictCode"
              :echo-value.sync="formData.buyChannel"
              multiple
              filterable
            ></CustomDictSelect>
          </el-form-item>
          <el-form-item prop="businessType1" label="一级业务类型">
            <CustomDictSelect
              placeholder="请选择"
              dict-type-code="FIRST_LEVEL_BUSINESS_TYPE"
              bind-name="dictName"
              bind-value="dictCode"
              :echo-value.sync="formData.businessType1"
              filterable
            ></CustomDictSelect>
          </el-form-item>
          <el-form-item prop="businessType2" label="二级业务类型">
            <CustomDictSelect
              placeholder="请选择"
              dict-type-code="SECOND_LEVEL_BUSINESS_TYPE"
              bind-name="dictName"
              bind-value="dictCode"
              :echo-value.sync="formData.businessType2"
              filterable
            ></CustomDictSelect>
          </el-form-item>
          <el-form-item>
            <Button @click="$refs.form.resetFields()">重置</Button>
            <ExportPane :table-config="tableConfig" :query-data-fun="queryHandle" filename="终端工单处理报表">导出</ExportPane>
            <Button type="primary" @click="queryHandle">查询</Button>
          </el-form-item>
        </el-form>
      </FormContainer>
      <table-box ref="table" no-request :other-filters="otherFilters" :table-config="tableConfig">

      </table-box>
    </ContentWrap>
    <Detail ref="detail" :row="row" :query-list="otherFilters" @close="row=undefined"></Detail>
  </div>
</template>
<script>
import ContentWrap from '@/components/ContentWrap'
import FormContainer from '@/components/FormContainer'
import ExportPane from '@/components/ExportPane'
import Button from '@/components/Button'
import CustomDictSelect from '@/components/CustomDictSelect'
import Detail from './detail'
// import SearchSelectPicker from '@/components/SearchSelectPicker'
import { filtersRaw } from '@/utils'
export default {
  name: 'ReportFormClientOrderHand',
  components: {
    ContentWrap,
    FormContainer,
    Button,
    // SearchSelectPicker,
    ExportPane,
    CustomDictSelect,
    Detail
  },
  data() {
    return {
      formData: {
        buyChannel: []
      },
      formRules: {
        queryDate: {
          required: true,
          message: '请选择派单日期',
          trigger: 'change'
        },
        operationMode: {
          required: true,
          message: '请选择统计对象',
          trigger: 'change'
        },
        disCode: {
          required: false,
          message: '请选择统经销商',
          trigger: 'change'
        }
      },
      otherFilters: [],
      tableConfig: {
        interfacePath: '/call-center/api/v2/workOrder/report/deal/page',
        pageFlag: true,
        hideFuncBar: true,
        // 表格字段动态配置
        setting: [
          {
            prop: 'statisticalObjectName',
            label: '统计对象',
            minWidth: 140,
            // isButton: true,
            // className: 'table-handelclick-text',
            // clickFun: this.columnClickHandle,
            render: (h, row) => {
              return h('span', {
                class: this.$style['table-handelclick-text'],
                on: {
                  click: e => {
                    e.stopPropagation()
                    this.columnClickHandle(row)
                  }
                }
              }, row.statisticalObjectName)
            }
          },
          {
            prop: 'addCount',
            label: '新增量',
            minWidth: 100
          },
          {
            prop: 'notTimelyCount',
            label: '不及时量',
            minWidth: 100
          },
          {
            prop: 'notTimelyRatio',
            label: '不及时占比',
            minWidth: 120
          },
          {
            prop: 'notTimelyRank',
            label: '不及时排名',
            minWidth: 120
          },
          {
            prop: 'finishCount',
            label: '结案量',
            minWidth: 100
          },
          {
            prop: 'processingCount',
            label: '处理中量',
            minWidth: 100
          },
          {
            prop: 'timeOutCount',
            label: '超时量',
            minWidth: 100
          },
          {
            prop: 'timeOutRatio',
            label: '超时占比',
            minWidth: 100
          },
          {
            prop: 'timeOutRank',
            label: '超时排名',
            minWidth: 100
          },
          {
            prop: 'overdueCount',
            label: '超期量',
            minWidth: 100
          },
          {
            prop: 'overdueRatio',
            label: '超期占比',
            minWidth: 100
          },
          {
            prop: 'overdueRank',
            label: '超期排名',
            minWidth: 100
          },
          {
            prop: 'notRepliedCount',
            label: '未回复量',
            minWidth: 100
          },
          {
            prop: 'timeOutRepliedCount',
            label: '超时回复量',
            minWidth: 120
          },
          {
            prop: 'timelyRepliedCount',
            label: '及时回复量',
            minWidth: 120
          },
          {
            prop: 'timelyRepliedRatio',
            label: '及时回复率',
            minWidth: 110
          },
          {
            prop: 'timelyRepliedRank',
            label: '及时回复率排名',
            minWidth: 140
          }
        ]
      },
      row: undefined
    }
  },
  mounted() {},
  methods: {
    // 根据条件查询
    queryHandle(type) {
      return this.$refs.form.validate().then(() => {
        const list = []
        for (const i in this.formData) {
          if (i === 'queryDate') {
            if (this.formData[i] && this.formData[i].length) {
              list.push(filtersRaw('beginDate', this.formData[i][0], '>='))
              list.push(filtersRaw('endDate', this.formData[i][1], '<='))
            }
          } else if (i === 'buyChannel') {
            const v = this.formData[i]
            if (v instanceof Array && v.length > 0) {
              list.push(filtersRaw(i, `[${v.join(',')}]`, 'in'))
            }
          } else {
            if (this.formData[i] || this.formData[i] === 0) {
              list.push(filtersRaw(i, this.formData[i], '='))
            }
          }
        }
        this.otherFilters = list
        if (type !== 'export') {
          this.$nextTick(() => {
            this.$refs.table.initTableData()
          })
        }
        return list
      })
    },
    columnClickHandle(row) {
      this.row = row
      this.$refs.detail.showDetail()
    }
  }
}
</script>
<style lang='scss' module>
.table-handelclick-text {
    color: #3DC094;
    cursor: pointer;
  }
</style>
